import http from '@/utils/typedHttp';
import { IssueSeverity, IssueType } from '@/types/aiCorrector';


export interface IssueResponse {
  id: string;
  plan_id: string;
  item_id: string;
  type: IssueType;
  severity: IssueSeverity;
  title: string;
  description: string;
  suggestion: string;
  original_content?: string;
  original_description?: string;
}

/**
 * 获取当前未处理的问题列表
 */
export const getIssuesAPI = async (planId: string): Promise<IssueResponse[]> => {
  try {
    return await http.get<IssueResponse[]>(`/issues/plan/${planId}`);
  } catch (error) {
    // 由上层捕获并处理
    throw error;
  }
};

/**
 * 批量删除（或标记已解决）问题
 * @param issueIds 要删除 / 标记完成的 issue ID 列表
 */
export const deleteIssuesAPI = async (issueIds: string[]): Promise<void> => {
  try {
    if (issueIds.length === 0) return;
    // 后端 DELETE /issues 接收 JSON body: { ids: [...] } 
    await http.delete('/issues/', { data: { ids: issueIds } } as any);
  } catch (error) {
    throw error;
  }
};
